package com.doudou.mybatis.mate.boot.starter.interceptor;

import com.doudou.mybatis.mate.core.interceptors.DesensitizeInterceptor;
import com.doudou.mybatis.mate.core.interceptors.FieldFillInterceptor;
import com.doudou.mybatis.mate.core.interceptors.LogInterceptor;
import com.doudou.mybatis.mate.core.interceptors.PageInterceptor;
import org.apache.ibatis.plugin.Interceptor;

import java.util.HashMap;
import java.util.Map;

/**
 * InterceptorFactory
 *
 * @author jiangcs
 * @since 2022/4/7
 */
public class InterceptorFactory {
    private static final Map<String, Interceptor> INTERCEPTOR_MAP = new HashMap<>();

    static {
        // 分页
        INTERCEPTOR_MAP.put("page", new PageInterceptor());
        // 字段填充
        INTERCEPTOR_MAP.put("filedFill", new FieldFillInterceptor());
        // 脱敏
        INTERCEPTOR_MAP.put("desensitize", new DesensitizeInterceptor());
        // 日志
        INTERCEPTOR_MAP.put("log", new LogInterceptor());
    }

    public static Interceptor getInstance(String name) {
        for (String key : INTERCEPTOR_MAP.keySet()) {
            if (name.equals(key)) {
                return INTERCEPTOR_MAP.get(key);
            }
        }
        return null;
    }
}
